package org.crystal.tradecraft.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import org.crystal.tradecraft.model.binance.market.KLine;
import org.crystal.tradecraft.serialization.InstantDeserializer;
import org.crystal.tradecraft.serialization.InstantSerializer;
import org.ta4j.core.Bar;
import org.crystal.tradecraft.serialization.BarDeserializer;
import org.crystal.tradecraft.serialization.BinanceKLineDeserializer;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.time.Instant;

@UtilityClass
public class TradeCraftUtils {

    public static final ObjectMapper GLOBAL_OBJECT_MAPPER = new ObjectMapper()
        .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
        .registerModules(new Jdk8Module(), new JavaTimeModule(), new SimpleModule()
            .addDeserializer(KLine.class, new BinanceKLineDeserializer())
            .addDeserializer(Instant.class, new InstantDeserializer())
            .addDeserializer(Bar.class, new BarDeserializer())
            .addSerializer(Instant.class, new InstantSerializer()));

    @SneakyThrows
    public static KeyPair generateRsaKey() { 
		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
		keyPairGenerator.initialize(2048);
		return keyPairGenerator.generateKeyPair();
	}
}
